import Vue from 'vue'
import VueRouter from 'vue-router'

// 导入视图组件
const Home = () => import('../views/Home.vue')
const NoteList = () => import('../views/notes/NoteList.vue')
const KnowledgeList = () => import('../views/KnowledgeList.vue')
const AddPage = () => import('../views/addpage.vue')
const ExcalidrawDemo = () => import('../views/ExcalidrawDemo.vue')
const testCom = () => import('../views/test.vue')
const demoMeetingCom = () => import('../views/metting/demo.vue')

Vue.use(VueRouter)

/**
 * 路由配置
 * @type {Array}
 */
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: { title: '首页' }
  },
  {
    path: '/notes',
    name: 'NoteList',
    component: NoteList,
    meta: { title: '笔记列表' }
  },
  {
    path: '/knowledge',
    name: 'KnowledgeList',
    component: KnowledgeList,
    meta: { title: '知识库管理' }
  },
  {
    path: '/knowledge/add',
    name: 'AddPage',
    component: AddPage,
    meta: { title: '新增文章' }
  },
  {
    path: '/excalidraw-demo',
    name: 'ExcalidrawDemo',
    component: ExcalidrawDemo,
    meta: { title: 'Excalidraw组件演示' }
  },
  {
    path: '/test',
    name: 'test',
    component: testCom,
    meta: { title: '测试' }
  },
    {
    path: '/demoMeetingCom',
    name: 'demoMeetingCom',
    component: demoMeetingCom,
    meta: { title: '测试' }
  },
  

  // 重定向到首页
  {
    path: '*',
    redirect: '/'
  }
]

const router = new VueRouter({
  routes
})

// 路由前置守卫，设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = `${to.meta.title} - 后台管理系统`
  }
  next()
})

export default router
